
#include <iostream>
#include <cassert>
#include <chrono>
#include <vector>
using namespace std;
using namespace std::chrono;

struct point
{
    double x, y, z;
};

#define _STRUCT_
// #define _PTR_
#define _VECTOR_

/**
 * @brief  测试 struct 和 数组那个有效果
 * 
 * array  |  struct
 * 10000000
 * 0.22 | 0.22
 * 1e8
 * 2.15 | 2.10
 * -O1
 * 0.91 | 0.91
 * -O2
 * 一样
 * @return 两者效率相同
 */

int main()
{

    constexpr int num{1000000000};
#ifdef _STRUCT_
#ifndef _VECTOR_
    point *arr{new point[num]};
#else
    vector<point> arr(num);
#endif
    auto t1 = steady_clock::now();

    for (int i = 0; i < num; ++i)
    {
        arr[i].x = i;
        arr[i].y = i + 1;
        arr[i].z = i + 2;
    }
    auto t2 = steady_clock::now();

#else
    double(*arr)[3] = new double[num][3];
    auto t1 = steady_clock::now();
    for (int i = 0; i < num; ++i)
    {
        arr[i][0] = i;
        arr[i][1] = i + 1;
        arr[i][2] = i + 2;
    }
    auto t2 = steady_clock::now();
#endif
    duration<double> dt = duration_cast<duration<double>>(t2 - t1);
    cout << "\n"
         << dt.count() << "\n";
    return 0;
}